cmake_minimum_required(VERSION 3.10)

# set the project name and version
project(Tutorial VERSION 1.0)

# specify the C++ standard
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)

# should we use our own math functions
option(USE_MYMATH "Use Demo provided math implementation" ON)

# configure a header file to pass some of the CMake settings
# to the source code
# 配置头文件设置文件ConfigHeader.h.in设置头文件
# ConfigHeader.h，两者名称需要对应
configure_file(ConfigHeader.h.in ConfigHeader.h)

# add the MathFunctions library
if(USE_MYMATH)
  add_subdirectory(MathFunctions)
  list(APPEND EXTRA_LIBS MathFunctions)
  list(APPEND EXTRA_INCLUDES "${PROJECT_SOURCE_DIR}/MathFunctions")
endif()

# add the executable
add_executable(Demo tutorial.cxx)

target_link_libraries(Demo PUBLIC ${EXTRA_LIBS})

# add the binary tree to the search path for include files
# so that we will find ConfigHeader
target_include_directories(Demo PUBLIC
                           "${PROJECT_BINARY_DIR}"
                           ${EXTRA_INCLUDES})
# 添加安装目录
install(TARGETS Demo DESTINATION bin)
install(FILES "${PROJECT_BINARY_DIR}/ConfigHeader.h"
  DESTINATION include
  )

set(_VERSION_MAJOR 1)
set(_VERSION_MINOR 1)
set(_VERSION_PATCH 0)

#说明要生成的是deb包
set(CPACK_GENERATOR "DEB")

############下面是设置debian/control文件中的内容

#设置版本信息
set(CPACK_PACKAGE_VERSION_MAJOR "${_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${_VERSION_MINOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${_VERSION_PATCH}")

#设置安装包的包名，打好的包将会是Demo-version-linux.deb，如果不设置，默认是工程名
set(CPACK_PACKAGE_NAME "Demo")

#设置程序名，就是程序安装后的名字
set(CPACK_DEBIAN_PACKAGE_NAME "projectname")

#设置架构
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64")

#设置依赖
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6, libstdc++6")

#设置section
set(CPACK_DEBIAN_PACKAGE_SECTION "net")

#设置priority
set(CPACK_DEBIAN_PACKAGE_PRIORITY "Optional")

#设置description
set(CPACK_PACKAGE_DESCRIPTION "这时一个简单的包，实现对数求根号")

#设置联系方式
set(CPACK_PACKAGE_CONTACT "bleedingfight@126.com")

#设置维护人
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "bleedingfight@126.com")

##############debian/control设置完成了，下面设置控制脚本，动态库，changelog等

#lib目录下保存这一些动态库和安装控制脚本（postinst、postrm、preinst、prerm）  doc目录下是changelog和copyright等文件 这些东西是打包时要依赖的一些额外的东西
set(LIBS_DIR ${CMAKE_BINARY_DIR}/MathFunctions)
set(DOCS_DIR ${CMAKE_SOURCE_DIR}/doc)

#设置控制脚本，这些都是大包者本人自己准备的，没有就算了
# set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA
#  "${LIBS_DIR}/postinst;${LIBS_DIR}/postrm;${LIBS_DIR}/prerm")

#把动态库文件安装到指定的位置，这些动态库是程序必须依赖的且无法通过其他方法安装，所以我只能想到用这种笨办法来设置了。
install(FILES ${LIBS_DIR}/libMathFunctions.a DESTINATION lib)

#最后把我们的changelog等东西也加进来，project是你的工程名
# install(FILES ${DOCS_DIR}/changelog.Debian.gz ${DOCS_DIR}/changelog.gz ${DOCS_DIR}/copyright ${DOCS_DIR}/README.Debian DESTINATION /usr/share/doc/project)
include(CPack)